#include "./view.h"

/*********SGUI 进度条模板*******
占用资源：
obj->data[0] 按钮是否按下
obj->data[1] 按钮触发回调
obj->data[2] 按下时选中

obj->data[6] 拖拽状态
obj->data[7] 记录位置
obj->data[8] 记录位置
obj->data[9] 即时回调
回调函数：
sDragClick
按下，抬起共两次回调
******************************/

//创建拖拽
sObj*sGuiNewDragView(int x,int y,sSpr*spr,sDragClick click,int move)
{
 sObj*obj = sNewObj(x,y,spr);
 obj->eve = sGuiDragEve;
 obj->data[0] = FALSE;
 obj->data[1] = (int)click;
 obj->data[2] = FALSE;
 obj->data[6] = FALSE;
 obj->data[9] = move;
 return obj;
}

//监控拖拽
void sGuiDragEve(void*ob,int type,int p1,int p2)
{
 sObj*obj = ob;
 sBtnClick click = (sBtnClick)
 obj->data[1];
 int tmp = -1;
 //检测有没有按到
 tmp = 
 sPosCollObj(p1,p2,obj);
 switch(type)
 {
  //手移动和按下
  case MS_DOWN:
  if(tmp)
  {
   obj->data[0] = TRUE;
   obj->data[2] = TRUE;
   //按钮被按下瞬间
   if(obj->data[1]!=-1)
   	(*click)(obj,MS_DOWN);
   //开始拖拽
   obj->data[6] = TRUE;
   obj->data[7] = p1;
   obj->data[8] = p2;
  }
  break;
  
  //手指移动
  case MS_MOVE:
  //拖拽
  if(obj->data[6])
  {
   obj->x+=p1-obj->data[7];
   obj->y+=p2-obj->data[8];
   obj->data[7] = p1;
   obj->data[8] = p2;
   
   if(obj->data[9])
   	if(obj->data[1]!=-1)
   	(*click)(obj,MS_MOVE);
  }
  //未拖拽
  else
  {
   obj->data[0] = FALSE;
   obj->data[2] = FALSE;
  }
  break;
  
  case MS_UP:
  obj->data[0] = FALSE;
  //按钮内抬起 真单击事件
  if(tmp)
  {
   if(obj->data[1]!=-1)
   	if(obj->data[2]==TRUE)
   {
    click = (sBtnClick)
    obj->data[1];
    (*click)(obj,MS_UP);
    obj->data[6] = FALSE;
   }
  }
  if(obj->data[6])
  {
   (*click)(obj,MS_UP);
   obj->data[6] = FALSE;
  }
  break;
 }
}

